package cn.opopopo.design_pattern_learn.行为型.observer;

public class ObserverPatternDemo {
    public static void main(String[] args) {
        NewsPublisher publisher = new NewsPublisher();

        // 创建观察者（订阅者）
        MobileUser user1 = new MobileUser("张三");
        MobileUser user2 = new MobileUser("李四");
        EmailUser user3 = new EmailUser("wangwu@example.com");

        // 订阅新闻
        publisher.addObserver(user1);
        publisher.addObserver(user2);
        publisher.addObserver(user3);

        // 发布新闻
        publisher.publishNews("Java 21 新特性发布！");
        publisher.publishNews("Spring Boot 3.3 即将上线");

        // 某用户取消订阅
        publisher.removeObserver(user2);

        // 再次发布
        publisher.publishNews("观察者模式实战教程更新");
    }
}